<?php
namespace app\index\logic;
use app\index\validate\Visitor as VisitorValidate;

class OpenidLogic extends BaseLogic {

    /**
     * 检查保存微信用户规则
     * @param $params
     * @return mixed
     */
    public function check_save_visitor_rule($params){
        $validate = new VisitorValidate();
        $r = $validate->scene('add')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }
        return $this->get_response(1,'OK');
    }

    /**
     * 写入user表信息
     * @param $openid
     * @return mixed
     */
    public function add_user($openid){
        $maps = [];
        $maps[] = ['openid','=',$openid];
        $detail = model('user')->get_detail($maps,'id');
        if(empty($detail)){
            $u_data = [];
            $u_data['openid'] = $openid;
            $u_data['role'] = 5;
            $u_data['use_branchid'] = 0;
            $r = model('user')->insert($u_data);
            if(!$r){
                return $this->get_response(0,'进入系统失败');
            }
        }
        return $this->get_response(1,'进入系统成功');
    }
}